/***************************************************************************************
Firm-embedded productivity and cross-country income differences
Alviarez, Cravino and Ramondo
Journal of Political Economy (2022)

Program: figure_A1_coverage.do
Date: October 2022

Description: Reproduces Figure A.1: Data coverage: foreign-MNE revenues.

*****************************************************************************************/

*-------------------------------------------------------------------------------
global typeden=1
include "set_directories.do"
set memory 64g
global lf "LF"

*Log
cap log close
*log using "${clogs}/figure_A1_coverage.log",replace
*-------------------------------------------------------------------------------


etime, start 
use "${data}/orbis_mnc_agg.dta", clear
merge 1:1 year isocode using "${data}/oecd_eurostat_agg_mnc_output.dta"
drop if _merge==2
drop if _merge==1
drop _merge
order year isocode sales GO_usd_mnc emp EMPE_mnc 
format %9.0fc sales GO_usd_mnc emp EMPE_mnc 


gen cov_sales= sales / GO_usd_mnc
gen cov_emp= emp / EMPE_mnc
gen cov_final=cov_sales 

tab isocode if cov_final>1 & cov_final!=.
gsort -cov_final
replace cov_final=1 if cov_final>1 & cov_final!=.

merge 1:1 isocode using "${data}/countrycode_general.dta", keepusing(country isocode3)
drop if _merge==2
drop _merge
replace country="UK" if country=="United Kingdom"
replace country="Korea" if strpos(country, "Korea")>0

keep if isocode=="DK" | isocode=="JP" | isocode=="IT" | isocode=="KR" | isocode=="DE" | isocode=="FR" | isocode=="ES" |  isocode=="MX" |  isocode=="GB" |  isocode=="PL" |  isocode=="GR" |  isocode=="NL" |  isocode=="RO" |  isocode=="BE" |  isocode=="AT" |  isocode=="PT" |  isocode=="FI" |  isocode=="SE" |  isocode=="CZ" |  isocode=="SK" |  isocode=="BG" |  isocode=="HU" |  isocode=="HR" |  isocode=="LV" |  isocode=="SI" |  isocode=="LT" |  isocode=="EE" 
graph hbar cov_final, bar(1, color(red) fcolor(none) lwidth(medium))  yline(0) over( country , sort (cov_final) descending label(labsize(large)))  legend( region(lwidth(none)) size(large)  pos(6) label(1 "")) ytitle("")  scale(*.5) graphregion(color(white)) 

graph export "${rappendix}/fig_A1_coverage.pdf", replace

	
log close 
		 

